package com.dylan.历史.基础;

/**
 * Created by Dylan on 2018/9/4.
 */
public class 枚举 {

    public static void main(String[] args) {
        System.out.println(Season.SUMMER.getDesc());
        print(null);
        print(Season.AUTUMN);
    }

    static enum Season {
        SPRING("春"),
        SUMMER("夏"),
        AUTUMN("秋"),
        WINTER("冬");
        private String desc;
        Season(String desc) {
            this.desc = desc;
        }
        public String getDesc() {
            return this.desc;
        }
    }

    private static void print(Season season) {
        // 防止switch空指针异常
        if (season == null) return;

        switch (season) {
            case SPRING:
                System.out.println("春天放风筝");
            case SUMMER:
                System.out.println("夏天游泳");
//            case AUTUMN:
//                System.out.println("秋天捉知了");
            case WINTER:
                System.out.println("冬天滑冰");
            default:
                // 防止增加枚举条目时忘记修改的情况
                throw new IllegalArgumentException("未知枚举类型:" + season.name());
        }
    }
}
